package com.prs.crm.domain.purchase;

import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.FlowEntity;

@Entity
@Table(name="purchase_order")
public class Order extends FlowEntity {

	private static final long serialVersionUID = -4867503240956693033L;
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	private String name;
	private String code;
	@OneToMany(fetch=FetchType.LAZY)
	@JoinTable(
			name="purchase_order_supplierinquiry",
			joinColumns={@JoinColumn(name="order_id")},
			inverseJoinColumns={@JoinColumn(name="supplierinquiry_id")})
	private Set<SupplierInquiry> supplierInquirys;
	@ManyToOne(fetch=FetchType.LAZY)
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Attachment attach;
	@ManyToOne(fetch=FetchType.LAZY)
	private OrderType orderType;
	@Lob
	private String remark;
	
	private Date orderDate;
	
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public Attachment getAttach() {
		return attach;
	}
	public void setAttach(Attachment attach) {
		this.attach = attach;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public OrderType getOrderType() {
		return orderType;
	}
	public void setOrderType(OrderType orderType) {
		this.orderType = orderType;
	}
	public Date getOrderDate() {
		return orderDate;
	}
	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}
	public Set<SupplierInquiry> getSupplierInquirys() {
		return supplierInquirys;
	}
	public void setSupplierInquirys(Set<SupplierInquiry> supplierInquirys) {
		this.supplierInquirys = supplierInquirys;
	}
	
	public void addSupplierInquiry(SupplierInquiry supplierInquiry){
		if(supplierInquirys == null)
			supplierInquirys = new HashSet<SupplierInquiry>();
		supplierInquirys.add(supplierInquiry);
	}
	
	
	
	
	
	
}
